package com.yxd.server;

import com.yxd.logging.SysLogger;

import java.net.Socket;


/**
 * Created by Administrator on 2016/6/15.
 */
public class HttpWork implements Runnable {

    private final Socket socket;

    public HttpWork(Socket socket) {
        this.socket = socket;
    }

    public void doWork() {
        Thread thread = new Thread(this);
        thread.isDaemon();
        thread.start();
    }

    @Override
    public void run() {
        try {
            Request request = new Request(socket.getInputStream());
            request.parse();
            SysLogger.info("httpServer is accept a request:" + request.getUri());
            Response response = new Response(socket.getOutputStream());
            response.setRequest(request);
            Dispatcher.dispatch(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
